home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / context.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  3.9 KB  |  161 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      context
  20.    PURPOSE
  21.      
  22.    NOTES
  23.      
  24.    HISTORY
  25.      Terje Pedersen - Jun 29, 1995: Created.
  26. ***/
  27.  
  28. #include <intuition/intuition.h>
  29. #include <intuition/intuitionbase.h>
  30.  
  31. #include <graphics/gfx.h>
  32. #include <graphics/gfxbase.h>
  33. #include <graphics/gfxmacros.h>
  34. #include <graphics/displayinfo.h>
  35. #include <devices/timer.h>
  36.  
  37. #include <proto/intuition.h>
  38. #include <proto/graphics.h>
  39. #include <proto/gadtools.h>
  40. #include <proto/layers.h>
  41.  
  42. #include <dos.h>
  43. #include <signal.h>
  44. #include <stdlib.h>
  45. #include <time.h>
  46. #include <stdio.h>
  47.  
  48. #include "libX11.h"
  49.  
  50. #define XLIB_ILLEGAL_ACCESS 1
  51.  
  52. #include <X11/X.h>
  53. #include <X11/Xlib.h>
  54. #include <X11/Xutil.h>
  55. #include <X11/Intrinsic.h>
  56. #include <X11/IntrinsicP.h>
  57. #include <X11/CoreP.h>
  58.  
  59. #include "amigax_proto.h"
  60. #include "amiga_x.h"
  61.  
  62. #define MAXID 200
  63. #define MAXCONTEXT 5
  64. int X11resourceID[MAXID];
  65. int X11contextType[MAXID][MAXCONTEXT];
  66. char *X11contextData[MAXID][MAXCONTEXT];
  67. int X11numIDs=0;
  68.  
  69. int X11Quarks=1;
  70.  
  71. X11contextoverflow(d){
  72.   printf("Warning: context overflow(%d)..\n",d); getchar();
  73. }
  74.  
  75. XrmUniqueQuark(){/*          File 'xco.o' */
  76. #ifdef DEBUGXEMUL_ENTRY
  77.   printf("XrmUniqueQuark\n");
  78. #endif
  79. /*
  80.   int i;
  81.   for(i=0;i<X11numIDs;i++)
  82.     if(X11resourceID[i]==0){
  83.       return(i);
  84.     }
  85. */
  86.   return(X11Quarks++);
  87. }
  88.  
  89. X11findID(XID rid){
  90.   int i;
  91.   for(i=0;i<X11numIDs;i++)
  92.     if(X11resourceID[i]==rid) break;
  93.   if(i<X11numIDs) return(i);
  94.   else{
  95.     for(i=0;i<X11numIDs;i++)
  96.       if(X11resourceID[i]==0){
  97.     X11resourceID[i]=rid;
  98.     return(i);
  99.       }
  100.     X11resourceID[X11numIDs]=rid;
  101.     if(X11numIDs+1==MAXID){
  102.       X11contextoverflow(1);
  103.       return(X11numIDs);
  104.     }
  105.     return(X11numIDs++);
  106.   }
  107. }
  108.  
  109. int XSaveContext(display, rid, context, data)
  110.      Display *display;
  111.      XID rid;
  112.      XContext context;
  113.      caddr_t data;
  114. {/*            File 'xco.o' */
  115.   int id=X11findID(rid);
  116. #ifdef DEBUGXEMUL_ENTRY
  117.   printf("XSaveContext\n");
  118. #endif
  119.   if(context>=MAXCONTEXT) X11contextoverflow(2);
  120.   X11contextType[id][context]=context;
  121.   X11contextData[id][context]=data;
  122.   return(0);
  123. }
  124.  
  125. int XDeleteContext(display, rid, context)
  126.      Display *display;
  127.      XID rid;
  128.      XContext context;
  129. {/*          File 'xco.o' */
  130.   int id=X11findID(rid);
  131. #ifdef DEBUGXEMUL_ENTRY
  132.   printf("XDeleteContext\n");
  133. #endif
  134.   if(context>=MAXCONTEXT)X11contextoverflow(3);
  135.   X11contextType[id][context]=0;
  136.   free(X11contextData[id][context]);
  137.   X11contextData[id][context]=NULL;
  138.   X11resourceID[id]=0;
  139.   return(0);
  140. }
  141.  
  142. int XFindContext(display, rid, context, data_return)
  143.      Display *display;
  144.      XID rid;
  145.      XContext context;
  146.      XPointer *data_return;
  147. {/*            File 'xgraph.o' */
  148.   int i;
  149. #ifdef DEBUGXEMUL_ENTRY
  150.   printf("XFindContext\n");
  151. #endif
  152.   for(i=0;i<X11numIDs;i++)
  153.     if(X11resourceID[i]==rid) break;
  154.   if(i==X11numIDs) return(1);
  155.   if(context>=MAXCONTEXT)X11contextoverflow(4);
  156.   *data_return=X11contextData[i][context];
  157.   if(*data_return==0) return(1);
  158.   return(0);
  159. }
  160.  
  161.